﻿/*
* Copyright (C) 2020 ~ 2024 chaigec All Rights Reserved.
*
* Author:     chaigec <chaigec@163.com>
* Maintainer: chaigec <chaigec@163.com>

 * Use of this source code is governed by MIT license that can be found in the
 * LICENSE file in the root of the source tree. All contributing project authors
 * may be found in the AUTHORS file in the root of the source tree.
*/

#include "MkRwLock.h"

CMkRwLock::CMkRwLock()
{
#ifdef _WIN32
    //InitializeSRWLock(&m_mutex);
#else
    pthread_rwlock_init(&m_mutex, nullptr);
#endif
}

CMkRwLock::~CMkRwLock()
{
#ifdef _WIN32
#else
    pthread_rwlock_destroy(&m_mutex);
#endif
}

void CMkRwLock::RLock()
{
#ifdef _WIN32
    //quireSRWLockShared(&m_mutex);
    m_mutex.lock_shared();
#else
    pthread_rwlock_rdlock(&m_mutex);
#endif
}

void CMkRwLock::RUnlock()
{
#ifdef _WIN32
    //eleaseSRWLockShared(&m_mutex);
    m_mutex.unlock_shared();
#else
    pthread_rwlock_unlock(&m_mutex);
#endif
}

void CMkRwLock::WLock()
{
#ifdef _WIN32
    //AcquireSRWLockExclusive(&m_mutex);
    m_mutex.lock();
#else
    pthread_rwlock_wrlock(&m_mutex);
#endif
}

void CMkRwLock::WUnlock()
{
#ifdef _WIN32
    //ReleaseSRWLockExclusive(&m_mutex);
    m_mutex.unlock();
#else
    pthread_rwlock_unlock(&m_mutex);
#endif
}
